/*** Utility Types ***/
#ifndef _LLIST_H_
#define _LLIST_H_

#ifdef __cplusplus
extern "C" {
#endif /** cplusplus **/

#include "libutil.h"

typedef struct lnode lnode_t;

struct lnode
{
  void *data;    /* A pointer to a generic sattelite data payload */ 
  lnode_t *next; /* A pointer to the next item in the list */
};

typedef struct
{
  lnode_t *head; /* A pointer to the head node of the list */
  lnode_t *foot; /* A pointer to the foot node of the list */
  int list_len;  /* Total number of items in the list */
} list_t;

/* Initialize a new singly linked list */
list_t *make_empty_list (void);
/* Free a list and all satellite data */
void free_list (list_t *list, void (*destroy_fptr)(void *));
/* Insert a new item into the list ordered according to the cmp function
 * pointer constraints. */
list_t *insert_in_order (list_t *list, void *value, 
                         int (*cmp_fptr)(const void *, const void *));
/* Insert a new item at the end of the current list */
list_t *insert_at_foot (list_t *list, void *value);
/* Find an item in the list, return NULL if not found */
void *find_element (list_t *list, void *value, 
                    int (*cmp_fptr)(const void *, const void *));
/* Insertion sort for link list items using a user defined cmp function */
list_t *sort_list (list_t *list, int (*cmp_fptr)(const void *, const void *));

#ifdef __cplusplus
}
#endif /** cplusplus **/

#endif /** _LLIST_H_ **/

